﻿using System;
using System.Data;
using System.Text;

using BizElements.Core.ProviderComponents;

namespace BizElements.Core
{
    /// <summary>
    /// Contains database column metadata and methods.
    /// </summary>
    public interface IDbColumn
    {
        #region Methods.

        /// <summary>Computes a string which is a combination of prefix (usually a table name) and column alias. Eg: Id -> MyTable_Id</summary>
        /// <returns>Prefixed alias.</returns>
        string GetPrefixedAlias();

        #endregion

        #region Properties.

        /// <summary>Gets or sets <see cref="IDbTable"/> object to which this column belongs to.</summary>
        IDbTable Table { get; set; }

        /// <summary>Gets the <see cref="DbType"/> of the column.</summary>
        DbType DbType { get; }

        /// <summary>Gets alias.</summary>
        string Alias { get; }

        /// <summary>Gets alias prefix. Eg: "MyTable_". Empty string if parent table is not set.</summary>
        string Prefix { get; }

        /// <summary>Gets the value that indicates whether null values are allowed in this column.</summary>
        bool IsNullable { get; }

        /// <summary>Gets the value that indicates whether the column automatically increments the value for new rows added to the table.</summary>
        bool AutoIncrement { get; }

        /// <summary>Gets the name of the column.</summary>
        string ColumnName { get; }

        /// <summary>Gets .NET type of data stored in the column.</summary>
        Type DataType { get; }

        /// <summary>Gets the default value for the column when creating new rows.</summary>
        object DefaultValue { get; }

        /// <summary>Gets the maximum length of a text column. Has no effect it it is not a text column.</summary>
        int MaxLengthIfText { get; }

        /// <summary>Gets the position of the column in the database table/view.</summary>
        int Ordinal { get; }

        /// <summary>Gets the value that indicates whether the column is a part of the primary key.</summary>
        bool IsPrimaryKeyPart { get; }

        /// <summary>Gets the value that indicates whether the column is a part of a foreign key.</summary>
        bool IsForeignKeyPart { get; }

        /// <summary>Gets the value that indicates whether the column is a part of a unique constraint.</summary>
        bool IsUniqueConstraintPart { get; }

        /// <summary>Gets the smallest possible value of this column.</summary>
        object MinValue { get; }

        /// <summary> Gets the smallest possible value of this column.</summary>
        object MaxValue { get; }

        /// <summary>Gets the name of the generated entity class property mapped to this column.</summary>
        string PropertyName { get; }

        /// <summary>Gets the value which indicates whether the value of the field is automatically generated by
        /// database (eg. timestamp or computed fields in SQL Server). 
        /// If set to true then this field's value cannot be inserted or updated. </summary>
        bool IsAutoGenerated { get; }

        /// <summary>Gets the sequence used to increment values for this field.
        /// <b>Null</b> if the column is not an auto-incremented field or if sequence is not used.</summary>
        string SequenceName { get; }

        /// <summary>Gets the collection of customized information associated with the column.</summary>
        /// <value>A IPropertyCollection with all custom information. <b>null</b> if no custom information is configured.</value>
        /// <remarks>The ExtendedProperties property lets you configure custom information for the column such as DBMS-specific properties.</remarks>
        IPropertyCollection<string> ExtendedProperties { get; }

        #endregion
    }
}